library(tidyverse)
library(readxl)
path = "Excel/800-899/831/831 Recaman Sequence.xlsx"
test = read_excel(path, range = "A1:A1001") %>% pull()
recaman_sequence <- function(n){
reduce(2:n,
.init = list(seq = 0L, seen = 0L),
.f = function(state, k){
seq <- state$seq
seen <- state$seen
prev <- last(seq)
cand <- prev - (k - 1L)
next_val <- if(cand > 0L && !(cand %in% seen)) cand else prev + (k - 1L)
list(seq = c(seq, next_val), seen = c(seen, next_val))
})$seq
}
result = recaman_sequence(1000)
all.equal(result, test)Excel BI - Excel Challenge 831
excel-challenges
excel-formulas
🔰 Find first 1000 terms of this sequence.

Challenge Description
🔰 Find first 1000 terms of this sequence.
Solutions
- Logic: Read the workbook ranges needed for the challenge.
- Strengths: The code maps the workbook rule into a compact, reproducible pipeline.
- Areas for Improvement: The solution assumes the workbook layout and selected ranges remain stable, so any structural change in the sheet would require small adjustments.
- Gem: The elegant part is how little code is needed once the correct intermediate representation is chosen.
import pandas as pd
path = "800-899/831/831 Recaman Sequence.xlsx"
test = pd.read_excel(path, usecols="A", nrows=1001).iloc[:, 0].tolist()
def recaman(n):
a=[0]; s={0}
for k in range(1,n):
x=a[-1]-k
a.append(x if x>0 and x not in s else a[-1]+k); s.add(a[-1])
return a
print(recaman(1000) == test) # TrueThe Python version keeps the algorithm explicit, which helps when the challenge depends on a greedy or iterative rule.
Difficulty Level
Easy / Medium
The business rule is clear, though the workbook still needs a few transformation steps to reach the expected output.